package com.yang.community.util;
import com.yang.community.entity.User;
import org.springframework.stereotype.Component;
/**
 * @Author: yang
 * @Description: 持有用户信息，代替session对象，因为这个是线程隔离的可以避免多线程对象拿错的问题
 * @Date: Created in 23:45 2022/8/1
 * @Modified By:
 */

@Component
public class HostHolder {
    // Thread先获取当前线程，然后获取当前线程的信息
    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }

}
